//
//  MainViewController.m
//  HouseShow
//
//  Created by  on 11-12-19.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "MainViewController.h"
#import "ASIHTTPRequest.h"
#import "CJSONDeserializer.h"
#import "ASIFormDataRequest.h"
#import "HttpManageController.h"
#import "ImagesScrollViewController.h"
#import "LookRoomViewController.h"
#import "PInformationViewController.h"
#import "MortgageViewController.h"

#import "PresMovieController.h"

#define LeftMenuViewTag 0x10
#define ButtonInLabel 0x77

@interface MainViewController(private)
-(void) flowViewMoveInAnimate;
-(void) flowViewMoveOutAnimate;
-(void) addViewToFlow;
-(void) StarTimerToggle;
-(void) StopTimerToggle;
-(void) flowViewDidOut;
@end


@implementation MainViewController
@synthesize m_MageFolderPath;
@synthesize m_LeftMenusArr;
@synthesize m_LeftMenuFolderPath;
@synthesize m_OneListFolderPath;
@synthesize m_ListImgsArr;
@synthesize m_ShowSmallIndex;
@synthesize m_CallNextImgs;
-(void) viewDidLoad{
    self.navigationController.navigationBar.hidden = YES;
    //主菜单背景图
    UIImage* tBackGroundImg = [UIImage imageNamed:@"app_BackGround.png"];
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:tBackGroundImg]];
    
    //右上角文字图
    UIImageView* tWordShow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"app_BG_Word.png"]];
    tWordShow.frame =CGRectMake(760, 40, 232, 71);
    [self.view addSubview:tWordShow];
    [tWordShow release];
    
    
    p_OpenFlowView= [[AFOpenFlowView alloc] initWithFrame:CGRectMake(230,20,798,680)];
    p_OpenFlowView.viewDelegate = self;
    
    //左部分8按钮背景
    UIView* tLeftMenuBG = [[UIView alloc] initWithFrame:CGRectMake(-142, 0, 142, 768)];
    [tLeftMenuBG setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menu_BackGround.png"]]];
    tLeftMenuBG.tag = LeftMenuViewTag;
    [self.view addSubview:tLeftMenuBG];
    [tLeftMenuBG release];
    
    
    p_ChoicedStateImg = [UIImage imageNamed:@"choiced.png"];
    p_NoneChoicedStateImg = [UIImage imageNamed:@"nonechoiced.png"];

    p_ChoicedStateWordColor = [UIColor colorWithRed:56/255.f green:22/255.f blue:7/255.f alpha:1.0];
    [p_ChoicedStateWordColor retain];
    p_NoneChoicedStateWordColor = [UIColor whiteColor];
    [p_NoneChoicedStateWordColor retain];
    
    p_LeftNButtonImgs = [[NSMutableArray alloc] init];
    p_LeftCButtonImgs = [[NSMutableArray alloc] init];
    m_ListImgsArr = [[NSMutableArray alloc] init];
    
    NSFileManager* tFileMan = [NSFileManager defaultManager];
    NSString* tMenuPathDoc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    ASIHTTPRequest* tFlashRequest =[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://www.unitrue.com.cn:8088/ClientWebPage/UpWebPage.aspx"]];
    [tFlashRequest startSynchronous];
    NSArray* tArray = [tFlashRequest responseCookies];
    for (NSHTTPCookie* tCookie in tArray) {
        NSLog(@"%@",[tCookie.properties description]);
        if ([tCookie.name isEqualToString:@"opresult"]) {
            if ([tCookie.value isEqualToString:@"true"]) {
                NSArray* tFilesArr = [tFileMan contentsOfDirectoryAtPath:tMenuPathDoc error:nil];
                NSLog(@"%@",[tFilesArr description]);
                for (NSString* path in tFilesArr) {
                    NSString* tDeleteStr =[tMenuPathDoc stringByAppendingPathComponent:path];
                    [tFileMan removeItemAtPath:tDeleteStr error:nil];
                }
            }
        }
    }
    
    //创建文件夹
    self.m_LeftMenuFolderPath = [tMenuPathDoc stringByAppendingPathComponent:@"LeftMenu"];
    [tFileMan createDirectoryAtPath:m_LeftMenuFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
    self.m_OneListFolderPath = [tMenuPathDoc stringByAppendingPathComponent:@"listImgs"];
    [tFileMan createDirectoryAtPath:m_OneListFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
    self.m_MageFolderPath = [tMenuPathDoc stringByAppendingPathComponent:@"magedata"];
    [tFileMan createDirectoryAtPath:m_MageFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
    
    //下按钮部分
    for (int i=0; i<3; i++) {
        UIButton* tButt =[UIButton buttonWithType:UIButtonTypeCustom];
        NSString* tCImgName = [NSString stringWithFormat:@"down_CButton%d",i];
        NSString* tNImgName = [NSString stringWithFormat:@"down_NButton%d",i];
        NSString* tCImgPath = [[NSBundle mainBundle] pathForResource:tCImgName ofType:@"png"]; 
        NSString* tNImgPath = [[NSBundle mainBundle] pathForResource:tNImgName ofType:@"png"];
        [p_LeftNButtonImgs addObject:[UIImage imageWithContentsOfFile:tNImgPath]];
        [p_LeftCButtonImgs addObject:[UIImage imageWithContentsOfFile:tCImgPath]];
        [tButt setImage:[p_LeftNButtonImgs lastObject] forState:UIControlStateNormal];
        tButt.frame =CGRectMake(600+i*134, 710, 124, 36);
        tButt.tag = i;
        [self.view addSubview:tButt];
        [tButt addTarget:self action:@selector(pressDownButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    p_ManageHttp = [[HttpManageController alloc] init];
    p_ManageHttp.m_MainVC = self;
    
    [p_ManageHttp requestFlowImageData];
    
    m_CallNextImgs= false;
}

-(void) viewDidAppear:(BOOL)animated{
    if (animated) {
        if (!p_PresendMode) {
            p_OpenFlowView= [[AFOpenFlowView alloc] initWithFrame:CGRectMake(230,20,798,680)];
            p_OpenFlowView.viewDelegate = self;
            [p_ManageHttp showImgsCheck:m_ShowSmallIndex];
        }
    }
}


-(void) dealloc{
    [p_ChoicedStateWordColor release];
    [p_NoneChoicedStateWordColor release];
    [p_ChoicedStateImg release];
    [p_NoneChoicedStateImg release];
    [ditu release];
    [mortagge release];
    [p_ImgScrollViewController release];
    [p_ClockTimer invalidate];
    [p_ClockTimer release];
    [m_LeftMenusArr release];
    [m_LeftMenuFolderPath release];
    [m_OneListFolderPath release];
    [m_ListImgsArr release];
    [p_ManageHttp release];
    [p_OpenFlowView release];
    [p_LeftNButtonImgs release];
    [p_LeftCButtonImgs release];
    [super dealloc];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return UIDeviceOrientationLandscapeLeft == interfaceOrientation;
}


//左主菜单按钮响应
-(void) pressLeftButton:(UIButton*)sender {

    UIView* tMenuView = [self.view viewWithTag:LeftMenuViewTag];
    UIButton* tLastButton = (UIButton*)[tMenuView viewWithTag:m_ShowSmallIndex];
    
    [tLastButton setImage:p_NoneChoicedStateImg forState:UIControlStateNormal];
    [sender setImage:p_ChoicedStateImg forState:UIControlStateNormal];
    
    UILabel* tLastInButtName = (UILabel*)[tLastButton viewWithTag:ButtonInLabel];
    [tLastInButtName setTextColor:p_NoneChoicedStateWordColor];
    UILabel* tNowInButtName = (UILabel*)[sender viewWithTag:ButtonInLabel];
    [tNowInButtName setTextColor:p_ChoicedStateWordColor];
    
    NSDictionary* tLeftMenuDic =  [m_LeftMenusArr objectAtIndex:sender.tag];
    int tIsVideo = [[tLeftMenuDic objectForKey:@"isvideo"] intValue];
    [p_ClockTimer invalidate];
    p_ClockTimer = nil;
    m_ShowSmallIndex = sender.tag;
    p_PresendMode = NO;
    if (tIsVideo == 0) {
        int isChildHave = [[tLeftMenuDic objectForKey:@"ischildnode"] intValue];
        NSLog(@"isChildHave =%d",isChildHave);
        if (isChildHave == 0) {
            p_Mazginetid =-1;
        }else{
            //杂志
            p_Mazginetid = sender.tag;
        }
        p_ManageHttp.m_InitFirst =YES;
        [self flowViewMoveOutAnimate];
    }else{
     //视频部分
        [p_OpenFlowView removeFromSuperview];
        [p_OpenFlowView release];
        p_OpenFlowView= nil;
        p_PresendMode =YES;
        
       PresMovieController* moviePlayer = [[PresMovieController alloc] init];
        moviePlayer.m_Tid =[tLeftMenuDic objectForKey:@"tid"];
        [self presentModalViewController:moviePlayer animated:YES];
        [moviePlayer release];
    }
}

//下菜单按钮响应
-(void) pressDownButton:(UIButton*)sender{
    if ([p_OpenFlowView superview] == nil && !p_PresendMode) {
        return;
    }
    [sender setImage:[p_LeftCButtonImgs objectAtIndex:sender.tag] forState:UIControlStateNormal];
    
    [self performSelector:@selector(changedImageToNormal:) withObject:sender afterDelay:0.2f];
    p_PresendMode = NO;
    if (sender.tag == 0) {
        p_PresendMode =YES;
        PInformationViewController*  pinfoview = [[PInformationViewController alloc] init];
        pinfoview.view.frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        [self.navigationController presentModalViewController:pinfoview animated:YES];
        [pinfoview release];
    }
    else if(sender.tag == 1)
    {
        if (ditu == nil) {
            ditu = [[LookRoomViewController alloc] init];
        }
        [ditu.name becomeFirstResponder];
        ditu.view.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
        [self.view addSubview:ditu.view];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2];
        ditu.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
    }
    else if(sender.tag == 2)
    {
        if (mortagge == nil) {
             mortagge = [[MortgageViewController alloc] init];
            [mortagge setBackgroundColor:[UIColor whiteColor]];
            UIView* tBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
            [tBackView setBackgroundColor:[UIColor blackColor]];
            tBackView.alpha = 0.5;
            mortagge.m_CountBackGroundView = tBackView;
            [tBackView release];
        }
        mortagge.frame = CGRectMake(150, ScreenHeight, ScreenWidth-300, ScreenHeight);
        [self.view addSubview:mortagge.m_CountBackGroundView];
        [self.view addSubview:mortagge];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2];
        mortagge.frame = CGRectMake(150, 0, ScreenWidth-300, ScreenHeight);
        [UIView commitAnimations];
    }
}
-(void) changedImageToNormal:(UIButton*)sender{
    [sender setImage:[p_LeftNButtonImgs objectAtIndex:sender.tag] forState:UIControlStateNormal];
}


//flowView 出现动画
-(void) flowViewMoveInAnimate{
    p_OpenFlowView.frame = CGRectMake(-100,300,798,680);
    p_OpenFlowView.alpha = 0.f;
    [self.view addSubview:p_OpenFlowView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(flowViewMoveInDone)];
    p_OpenFlowView.frame = CGRectMake(230, 20, 798, 680);
    p_OpenFlowView.alpha =1.f;
    [UIView commitAnimations];
}

-(void) flowViewMoveInDone{
    [self StarTimerToggle];
}

//flowView 消失动画
-(void) flowViewMoveOutAnimate{
    if ([p_OpenFlowView superview] != nil) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(flowViewDidOut)];
        p_OpenFlowView.frame = CGRectMake(230, 700, 798, 680);
        [UIView commitAnimations];
    }else{
        [self flowViewDidOut];
    }
}

-(void) flowViewDidOut{
    [p_OpenFlowView removeFromSuperview];
    [p_OpenFlowView release];
    p_OpenFlowView= nil;
    p_OpenFlowView= [[AFOpenFlowView alloc] initWithFrame:CGRectMake(230,20,798,680)];
    p_OpenFlowView.viewDelegate = self;
    if (p_Mazginetid < 0) {
        [p_ManageHttp showImgsCheck:m_ShowSmallIndex];
    }else{
        [p_ManageHttp requestForMagzine:m_ShowSmallIndex];
    }
    
}


//倒影小图flowview 开始进入
-(void) showSmallImgDone{
    NSDictionary* tFirstImgDic =[[m_ListImgsArr objectAtIndex:m_ShowSmallIndex] objectAtIndex:0];
    NSString* tFirstImgPath = [tFirstImgDic objectForKey:@"imgsrc"];
    UIImage* tImg = [UIImage imageWithData:[NSData dataWithContentsOfFile:tFirstImgPath]];
    [p_OpenFlowView setImage:tImg forIndex:0];
    [p_OpenFlowView setNumberOfImages:1];
    p_AddFlowViewCount = 0;
    [self flowViewMoveInAnimate];
}
//增加图片数
-(void) addViewToFlow{
    NSArray* tFirstImgArr =[m_ListImgsArr objectAtIndex:m_ShowSmallIndex];
    if ([tFirstImgArr isKindOfClass:[NSArray class]] && p_AddFlowViewCount+1 < [tFirstImgArr count]) {
        p_AddFlowViewCount++;
        NSDictionary* tNextImgDic = [tFirstImgArr objectAtIndex:p_AddFlowViewCount];
        NSString* tFirstImgPath = [tNextImgDic objectForKey:@"imgsrc"];
        UIImage* tImg = [UIImage imageWithData:[NSData dataWithContentsOfFile:tFirstImgPath]];
        [p_OpenFlowView setImage:tImg forIndex:p_AddFlowViewCount];
        [p_OpenFlowView setNumberOfImages:p_AddFlowViewCount+1];
        [p_OpenFlowView newImageMoveInAnimate:p_AddFlowViewCount];
    }else{
        [self StopTimerToggle];
    }
}

//菜单移动进来动画
-(void) leftMenuMoveAnimate{
    UIView* tMenuView = [self.view viewWithTag:LeftMenuViewTag];
    UIImageView* tTipImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menutip.png"]];
    tTipImg.tag =100;
    tTipImg.frame = CGRectMake(7, 84, 127, 48);
    [tMenuView addSubview:tTipImg];
    [tTipImg release];
    //左按钮部分
    int index = 0;
    for (NSDictionary* lmenuObject in m_LeftMenusArr) {
        UIButton* tButt =[UIButton buttonWithType:UIButtonTypeCustom];
        UILabel* tLabelName = [[UILabel alloc] initWithFrame:CGRectMake(14, 2, 127, 34)];
        if (index == 0) {
            [tButt setBackgroundImage:p_ChoicedStateImg forState:UIControlStateNormal];
            [tLabelName setTextColor:p_ChoicedStateWordColor];
        }else{
            [tButt setBackgroundImage:p_NoneChoicedStateImg forState:UIControlStateNormal];
            [tLabelName setTextColor:p_NoneChoicedStateWordColor];
        }
        tButt.frame =CGRectMake(7, 140+index*54, 127, 44);
        tButt.tag = index;
        [tMenuView addSubview:tButt];
        tButt.showsTouchWhenHighlighted = YES;
        [tButt addTarget:self action:@selector(pressLeftButton:) forControlEvents:UIControlEventTouchUpInside];
        NSString* tButtonNameStr = [lmenuObject objectForKey:@"tname"];
        
        [tLabelName setBackgroundColor:[UIColor clearColor]];
        [tLabelName setFont:[UIFont systemFontOfSize:24]];
        tLabelName.text = tButtonNameStr;
        tLabelName.tag = ButtonInLabel;
        
        [tButt addSubview:tLabelName];
        [tLabelName release];
        index++;
    }
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(leftMenuAnimateFinish)];
    tMenuView.frame = CGRectMake(80, 0, 142, 768);
    [UIView commitAnimations];
}

-(void) leftMenuAnimateFinish{
    [m_ListImgsArr removeAllObjects];
    for (int i=0; i<[m_LeftMenusArr count]; i++) {
        [m_ListImgsArr addObject:@"empty"];
    }
    m_ShowSmallIndex = 0;
    [p_ManageHttp showImgsCheck:0];
}

//创建右侧的图片列表本地化文件
-(void) createImgsListFolder{
    NSFileManager* tFileMan = [NSFileManager defaultManager];
    for (int i=0; i<[m_LeftMenusArr count]; i++) {
        NSString* tlistImgPath = [m_OneListFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"list%d",i]];
        [tFileMan createDirectoryAtPath:tlistImgPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
}

//定时器
-(void) StarTimerToggle{
    if (p_ClockTimer == nil) {
        p_ClockTimer = [NSTimer scheduledTimerWithTimeInterval:0.6f target:self selector:@selector(addViewToFlow) userInfo:nil repeats:YES];
        [p_ClockTimer retain];
        [p_ClockTimer fire];
    }
}

-(void) StopTimerToggle{
    if (p_ClockTimer != nil) {
        [p_ClockTimer invalidate];
        [p_ClockTimer release];
        p_ClockTimer = nil;
    }
}

#pragma mark DataSoure
- (UIImage *)defaultImage {
	return nil;
}

- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index {
    
}

#pragma mark delegate
- (void)openFlowView:(AFOpenFlowView *)openFlowView singleTaped:(int)index{
	NSLog(@"Cover Flow selection did change to %d", index);
    
    //
    if (p_Mazginetid >= 0) {
        //杂志请求
        NSString* tMageIndexList = [m_MageFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"mage%d.plist",index]];
        
        NSFileManager* tFileMan = [NSFileManager defaultManager];
        if ([tFileMan fileExistsAtPath:tMageIndexList]) {
            NSMutableArray* tMageBigs =[NSMutableArray arrayWithContentsOfFile:tMageIndexList];
            [p_ClockTimer invalidate];
            p_ClockTimer = nil;
            p_ManageHttp.m_InitFirst =YES;
            [p_OpenFlowView removeFromSuperview];
            [p_OpenFlowView release];
            p_OpenFlowView= nil;
            
            if (p_ImgScrollViewController != nil) {
                [p_ImgScrollViewController release];
                p_ImgScrollViewController = nil;
            }
            p_ImgScrollViewController = [[ImagesScrollViewController alloc] init];
            p_ImgScrollViewController.m_SrcData = [m_ListImgsArr objectAtIndex:p_Mazginetid];
            p_ImgScrollViewController.m_NowIndex = index;
            p_ImgScrollViewController.m_StartIndex = 0;
            p_ImgScrollViewController.m_ImagesDataArr =tMageBigs;
            p_ImgScrollViewController.m_PushNavigation = self.navigationController;
            [p_ImgScrollViewController setMagezin];
        }else{
            UIView* tNoOperView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
            tNoOperView.tag =0x188;
            [tNoOperView setBackgroundColor:[UIColor blackColor]];
            tNoOperView.alpha = 0.5;
            UIActivityIndicatorView* tLoadMage =[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(ScreenWidth/2-15, ScreenHeight/2-15, 30, 30)];
            [tLoadMage startAnimating];
            [tNoOperView addSubview:tLoadMage];
            [tLoadMage release];
            [self.view addSubview:tNoOperView];
            [tNoOperView release];
            
            NSArray* tMageArrData = [m_ListImgsArr objectAtIndex:p_Mazginetid];
            NSString* tTidName = [(NSDictionary*)[tMageArrData objectAtIndex:index] objectForKey:@"tid"];
            
            NSString* tRequestPath = [NSString stringWithFormat:@"http://www.unitrue.com.cn:8088/ClientWebPage/CNewsList.aspx?tid=%@&begin=1&end=20",tTidName];
            NSLog(@"tRequestPath =%@",tRequestPath);
            ASIHTTPRequest* tLeftImgsListRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:tRequestPath]];
            tLeftImgsListRequest.p_Tag = index;
            [tLeftImgsListRequest setDelegate:self];
            [tLeftImgsListRequest setDidFailSelector:@selector(requestMageImgs:)];
            [tLeftImgsListRequest setDidFinishSelector:@selector(requestMageImgsFinish:)];
            [tLeftImgsListRequest startAsynchronous];
        }
    }else{
        [p_ClockTimer invalidate];
        p_ClockTimer = nil;
        p_ManageHttp.m_InitFirst =YES;
        [p_OpenFlowView removeFromSuperview];
        [p_OpenFlowView release];
        p_OpenFlowView= nil;
        
        if (p_ImgScrollViewController != nil) {
            [p_ImgScrollViewController release];
            p_ImgScrollViewController = nil;
        }
        p_ImgScrollViewController = [[ImagesScrollViewController alloc] init];
        p_ImgScrollViewController.m_StartIndex = index;
        NSMutableArray* tImgsListArr =  [m_ListImgsArr objectAtIndex:m_ShowSmallIndex];
        p_ImgScrollViewController.m_ImagesDataArr =tImgsListArr;
        p_ImgScrollViewController.m_PushNavigation = self.navigationController;
    }
}

//杂志数据获得失败 
-(void) requestMageImgs:(ASIHTTPRequest*) request{
    NSLog(@"杂志数据获得失败");
    [[self.view viewWithTag:0x188] removeFromSuperview];
}
//杂志数据得成功
-(void) requestMageImgsFinish:(ASIHTTPRequest*) request{
    NSString* httpdata = [request responseString];
	NSLog(@"http context = %@",httpdata);
	NSData *jsonData = [httpdata dataUsingEncoding:NSUTF32BigEndianStringEncoding];
	NSError *error = nil;
	NSDictionary* tDataDic = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] ;
    NSMutableArray* tTempArr = nil;
    NSArray* tMageArrData = [m_ListImgsArr objectAtIndex:p_Mazginetid];

	if (error == nil) {
        NSString* tTidName = [(NSDictionary*)[tMageArrData objectAtIndex:request.p_Tag] objectForKey:@"tid"];
        NSArray* tDataImgsArr = [tDataDic objectForKey:tTidName];
        tTempArr = [NSMutableArray arrayWithArray:tDataImgsArr];
        
        NSString* tMageIndexList = [m_MageFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"mage%d.plist",request.p_Tag]];
        [tTempArr writeToFile:tMageIndexList atomically:YES];
    }
    [[self.view viewWithTag:0x188] removeFromSuperview];
    
    [p_ClockTimer invalidate];
    p_ClockTimer = nil;
    p_ManageHttp.m_InitFirst =YES;
    [p_OpenFlowView removeFromSuperview];
    [p_OpenFlowView release];
    p_OpenFlowView= nil;
    
    if (p_ImgScrollViewController != nil) {
        [p_ImgScrollViewController release];
        p_ImgScrollViewController = nil;
    }
    p_ImgScrollViewController = [[ImagesScrollViewController alloc] init];
    p_ImgScrollViewController.m_SrcData = tMageArrData;
    p_ImgScrollViewController.m_StartIndex = 0;
    p_ImgScrollViewController.m_NowIndex = request.p_Tag;
    p_ImgScrollViewController.m_ImagesDataArr =tTempArr;
    p_ImgScrollViewController.m_PushNavigation = self.navigationController;
    [p_ImgScrollViewController setMagezin];
}

-(void) relashEGOView:(NSInteger)tIndex Page:(NSInteger)tPage{
    NSString* tMageIndexList = [m_MageFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"mage%d.plist",tIndex]];
    NSMutableArray* tMageBigs =[NSMutableArray arrayWithContentsOfFile:tMageIndexList];
    [p_ClockTimer invalidate];
    p_ClockTimer = nil;
    p_ManageHttp.m_InitFirst =YES;
    [p_OpenFlowView removeFromSuperview];
    [p_OpenFlowView release];
    p_OpenFlowView= nil;
    
    [self.navigationController popViewControllerAnimated:NO];
    
    if (p_ImgScrollViewController != nil) {
        [p_ImgScrollViewController release];
        p_ImgScrollViewController = nil;
    }
    p_ImgScrollViewController = [[ImagesScrollViewController alloc] init];
    p_ImgScrollViewController.m_SrcData = [m_ListImgsArr objectAtIndex:p_Mazginetid];;
    p_ImgScrollViewController.m_StartIndex = 0;
    p_ImgScrollViewController.m_NowIndex = tIndex;
    p_ImgScrollViewController.m_ImagesDataArr =tMageBigs;
    p_ImgScrollViewController.m_PushNavigation = self.navigationController;
    [p_ImgScrollViewController setMagezin];
    
}

#pragma -
#pragma UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == Alert_Menu) {
        exit(0);
    }
}



@end
